package com.qcby.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcby.admin.form.LinkPageForm;
import com.qcby.admin.model.SgLink;
import com.qcby.admin.dao.SgLinkMapper;
import com.qcby.admin.service.SgLinkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.admin.vo.LinkPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 友链 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-09-23
 */
@Service
public class SgLinkServiceImpl extends ServiceImpl<SgLinkMapper, SgLink> implements SgLinkService {
    @Autowired
    private SgLinkMapper linkMapper;

    @Override
    public LinkPageVo linkList(LinkPageForm linkPageForm) {
        Page<SgLink> page=new Page<>(linkPageForm.getPageNum(),linkPageForm.getPageSize());
        LambdaQueryWrapper<SgLink> lqw=new LambdaQueryWrapper();
        lqw.like(StringUtils.hasText(linkPageForm.getName()),SgLink::getName,linkPageForm.getName());
        lqw.eq(StringUtils.hasText(linkPageForm.getStatus()),SgLink::getStatus,linkPageForm.getStatus());
        page=linkMapper.selectPage(page,lqw);
        LinkPageVo linkPageVo=new LinkPageVo();
        linkPageVo.setRows(page.getRecords());
        linkPageVo.setTotal(page.getTotal());
        return linkPageVo;
    }
}
